# Table 3

rm(list=ls(all=TRUE))

require(survival)
require(sjPlot)
library(ggpubr)

#### Datasets ####
setwd("/Users/sebastian/Dropbox/The politics of interruptions - JOP RR/Replication Files/Data Rep")
load("data_empirics_survival_rep.Rdata") 

#### 

model_4.2 <- coxph(Surv(time_elapsed) ~ female_dum + ideology_ext +
                     committee_chair + seniority + type_member +
                     party_match_pres +
                     election_year + length_speech_combined_100 +
                     tot_num_speeches_session_10 + mean_length_leg +
                     negative_lang_leg_session + dum_mujeres_session +
                     interruption_dummy_session + female_dum*interruption_dummy_session 
                   , data = data_empirics_survival)

model_4.4 <- coxph(Surv(time_elapsed) ~ female_dum + ideology_ext +
                     committee_chair + seniority + type_member +
                     party_match_pres +
                     election_year + length_speech_combined_100 +
                     tot_num_speeches_session_10 + mean_length_leg +
                     negative_lang_leg_session + dum_mujeres_session +
                     procedural_dummy_session + procedural_dummy_session*female_dum 
                   , data = data_empirics_survival)

model_4.6 <- coxph(Surv(time_elapsed) ~ female_dum + ideology_ext +
                     committee_chair + seniority + type_member + 
                     party_match_pres +
                     election_year + length_speech_combined_100 +
                     tot_num_speeches_session_10 + mean_length_leg +
                     negative_lang_leg_session + dum_mujeres_session +
                     aggressive_dummy_session + aggressive_dummy_session*female_dum 
                   , data = data_empirics_survival)

#### FIGURE 2: Length of speech before interruption ####
setwd("/Users/sebastian/Dropbox/The politics of interruptions - JOP RR/Replication Files/Figures")

risk_1 <- plot_model(model_4.2, type = "pred", terms = c("interruption_dummy_session","female_dum"), axis.lim = c(0.55,1.25)) +
  labs(x = "", y = "Risk Scores",
       title = "Predicted Risk Scores After\nBeing Interrupted (All)") +
  scale_x_discrete(limits = c("Not Interrupted", "Interrupted"),
                   expand=c(0.5, 0)) +
  geom_hline(yintercept = 1, lty = 2, color = "black")+
  theme(legend.position="bottom",
        legend.title = element_blank()) 

risk_2 <-plot_model(model_4.4, type = "pred", terms = c("procedural_dummy_session","female_dum"), axis.lim = c(0.55,1.25)) +
  labs(x = "", y = "Risk Scores",
       title = "Predicted Risk Scores After\nBeing Procedurally Interrupted") +
  scale_x_discrete(limits = c("Not Interrupted", "Interrupted"),
                   expand=c(0.5, 0)) +
  geom_hline(yintercept = 1, lty = 2, color = "black")+
  theme(legend.position="bottom",
        legend.title = element_blank())

risk_3 <-plot_model(model_4.6, type = "pred", terms = c("aggressive_dummy_session","female_dum"), axis.lim = c(0.55,1.25)) +
  labs(x = "", y = "Risk Scores",
       title = "Predicted Risk Scores After\nBeing Aggressively Interrupted") +
  scale_x_discrete(limits = c("Not Interrupted", "Interrupted"),
                   expand=c(0.5, 0)) +
  geom_hline(yintercept = 1, lty = 2, color = "black")+
  theme(legend.position="bottom",
        legend.title = element_blank())

### All together now:
combined_risk <- ggarrange(risk_1, risk_2,
                           risk_3,
                           # labels = c("Chile","Ecuador"),
                           ncol = 1, nrow = 3,common.legend = T,
                           legend = "bottom",
                           font.label = list(face = "plain", 
                                             size = 12))

combined_risk
ggsave("figure2.pdf", width = 12, height = 6)
